<?php 
class User extends BaseController_Controller {	

	public function __construct()
	{
		parent::__construct();			
		$this->load->library('sys/sysuser');		 
	}

	public function index()
	{		
		$this->appendhtmlwithjs('',$data,'admin/user.js',false);
	}

	public function delete()
	{		
		$id=json_decode($this->input->post('cb'),true);	
		if(count($id)>0)
		{
			$muser=new SysUser();
			$rslt['success']=$muser->Delete($id);			
		}
		echo json_encode($rslt);
	}

	public function save()
	{		
		$muser=new SysUser( $this->input->post('uname'));
		$id=$muser->uname;
		$muser->uname=$this->input->post('uname');
		$muser->upassword=MD5($this->input->post('upassword'));
		$muser->empid=$this->input->post('empid');
		$muser->firstname=$this->input->post('firstname');
		$muser->midname=
		$muser->lastname=$this->input->post('lastname');
		$muser->email=$this->input->post('email');
	
		$b=false;
		if(!$id){		
			$b=$muser->Create($id);	
		}
		else{	
			$b=$muser->Update();	
		}

		$rslt=array();
		$rslt['success']=$b;

		echo json_encode($rslt);
	
	}	

	public function template()
	{
		$this->load->view('scp/hometemplate',$data);
	}

	function changepassword()
	{
		$cls=new SysUser($this->loginuser['uname']);
		
		$curpass=$this->input->post('hKLjhkljhgkGuhjVHGfdtrdyf');
		$newpass=$this->input->post('KJytgWwqUJGfHBvUgfnjHg');
		$confirmpass=$this->input->post('LKJJHgfNKNbgufjnbkjg');
		
		if($cls)
		{
			if($cls->upassword==MD5($curpass))
			{
				
				$rslt['success']=true;
				$rslt['message']='Success bro';
				
				
				if($newpass==$confirmpass )
				{
					if($newpass==$curpass)
					{
						$rslt['success']=false;
						$rslt['message']='The password you provide is same with old password';
					}
					else
					{
						$cls->upassword=MD5($newpass);
						$cls->ChangePassword();					
					}					
				}
				else
				{
					$rslt['success']=false;
					$rslt['message']='Password Not Match';
				}				
			}
			else	
			{				
				$rslt['success']=false;
				$rslt['message']='Invalid Existing Password';
			}
		}
		echo json_encode($rslt);		
	}
  }
